package com.yanqu.road.utils.serialize;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class StringToPropertyList extends JsonDeserializer<List<Property>> {
    @Override
    public List<Property> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
        String text = jsonParser.getText();
        String[] split = text.split("\\|");
        List<Property> list = new ArrayList<>();
        for (String s : split) {
            Property property = PropertyHelper.parseStringToProperty(s);
            list.add(property);
        }
        return list;
    }
}
